-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validator health status #3207
base: albatross
Are you sure you want to change the base?
Validator health status #3207
Conversation
f08b8d3
to
8108a5b
Compare
6978477
to
124258f
Compare
test-utils/src/validator.rs
Outdated
@@ -113,7 +113,7 @@ where | |||
let (v, c) = build_validator( | |||
peer_ids[i], | |||
Address::from(&validator_keys[i]), | |||
false, | |||
true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make automatic_reactivate
a fn param for build_validators
so it doesn't influence other tests?
validator/src/validator.rs
Outdated
/// The current validator health | ||
pub health: ValidatorHealth, | ||
/// Number of blocks that we have produced in time(without being inactivated) | ||
pub blk_cnt: u32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub blk_cnt: u32, | |
pub block_counter: u32, |
validator/src/micro.rs
Outdated
@@ -181,6 +198,8 @@ impl<TValidatorNetwork: ValidatorNetwork + 'static> NextProduceMicroBlockEvent<T | |||
continue; | |||
} | |||
|
|||
self.health_state.write().blk_cnt += 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.health_state.write().blk_cnt += 1; | |
self.health_state.write().blk_cnt.saturating_add(1); |
Prevent overflow
validator/src/micro.rs
Outdated
log::warn!(block = block.block_number(), "Not publishing block"); | ||
let event = ProduceMicroBlockEvent::MicroBlock; | ||
break Some(Some(event)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log::warn!(block = block.block_number(), "Not publishing block"); | |
let event = ProduceMicroBlockEvent::MicroBlock; | |
break Some(Some(event)); | |
log::warn!(block = block.block_number(), "Not publishing block"); | |
break Some(Some(ProduceMicroBlockEvent::MicroBlock)); |
validator/src/validator.rs
Outdated
pub health: ValidatorHealth, | ||
/// Number of blocks that we have produced in time(without being inactivated) | ||
pub blk_cnt: u32, | ||
/// For testing/debug purposes control wether produced blocks are published by the validator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// For testing/debug purposes control wether produced blocks are published by the validator | |
/// For testing/debug purposes control whether produced blocks are published by the validator |
validator/src/validator.rs
Outdated
pub struct HealthState { | ||
/// The current validator health | ||
pub health: ValidatorHealth, | ||
/// Number of blocks that we have produced in time(without being inactivated) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Number of blocks that we have produced in time(without being inactivated) | |
/// Number of subsequent blocks that we have been produced without being inactivated |
validator/src/validator.rs
Outdated
good_blocks = %self.health_state.read().blk_cnt, | ||
"Current validator health is yellow", | ||
); | ||
if self.health_state.read().blk_cnt >= VALIDATOR_HEALTH_THRESHOLD { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic doesn't seem to match with the original description: If the validator is Yellow and is not deactivated in a quarter of an epoch, we change its status to Green.
validator/src/validator.rs
Outdated
inactivated = red_block_number, | ||
"Current validator health is red", | ||
); | ||
if self.health_state.read().blk_cnt >= VALIDATOR_HEALTH_THRESHOLD { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic doesn't seem to match with the original description: If the validator is Red and is not deactivated in one epoch, we change its status to Yellow.
validator/src/validator.rs
Outdated
let validator_health = self.health_state.read().health; | ||
match validator_health { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let validator_health = self.health_state.read().health; | |
match validator_health { | |
match self.health_state.read().health { |
validator/src/validator.rs
Outdated
} | ||
ValidatorHealth::Red(_) => { | ||
log::warn!( | ||
"The validator needs human intervention, no automatic reactivate" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The validator needs human intervention, no automatic reactivate" | |
"The validator needs human intervention, no automatic reactivation" |
4bfe5c1
to
cccd5e5
Compare
60bc95c
to
0341c37
Compare
8fb7bd7
to
28c51c2
Compare
} | ||
|
||
/// This flag should only be used in tests context. | ||
pub fn _set_publish_flag(&mut self, publish: bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method can be annotated with #[cfg(test)]
such that it's only included in cargo test
and not in cargo build
.
@@ -46,6 +46,9 @@ use crate::{ | |||
/// in the first place. | |||
/// (**) The validator may be set to automatically reactivate itself upon inactivation. | |||
/// If this setting is not enabled the state change can only be triggered manually. | |||
/// However, there is a delay incurred if the validator is deactivated multiple consecutive times | |||
/// in the current epoch. The delay is function of the number of deactivations and is reduced |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// in the current epoch. The delay is function of the number of deactivations and is reduced | |
/// in the current epoch. The delay is a function of the number of deactivations and is reduced |
validator/src/health.rs
Outdated
|
||
use nimiq_keys::Address; | ||
|
||
/// Struct that represents the overall health of a validator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ValidatorHealthState
is an enum not a struct
validator/src/health.rs
Outdated
address: Address, | ||
/// Only used for testing purposes controls whether blocks are published by the validator | ||
publish: bool, | ||
/// Number of consecutive inactivations that have ocurred in the current epoch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Number of consecutive inactivations that have ocurred in the current epoch | |
/// Number of consecutive inactivations that have occurred in the current epoch |
validator/src/health.rs
Outdated
publish: bool, | ||
/// Number of consecutive inactivations that have ocurred in the current epoch | ||
inactivations: u32, | ||
/// Next block number where the re-activate transaction should be sent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Next block number where the re-activate transaction should be sent | |
/// Next block number indicating when the re-activate transaction should be sent |
validator/src/micro.rs
Outdated
@@ -181,6 +196,9 @@ impl<TValidatorNetwork: ValidatorNetwork + 'static> NextProduceMicroBlockEvent<T | |||
continue; | |||
} | |||
|
|||
// Each successfull block will decrease the number of inactivations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Each successfull block will decrease the number of inactivations | |
// Each successful block will decrease the number of inactivations |
validator/src/health.rs
Outdated
/// Increases the number of consecutive deactivations | ||
pub fn inactivate(&mut self, block_number: u32) { | ||
if !self.pending_reactivate { | ||
self.inactivations += 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saturating add?
validator/tests/mock.rs
Outdated
@@ -15,7 +15,7 @@ use nimiq_network_interface::{ | |||
}; | |||
use nimiq_network_libp2p::Network; | |||
use nimiq_network_mock::{MockHub, MockNetwork}; | |||
use nimiq_primitives::{networks::NetworkId, policy::Policy}; | |||
use nimiq_primitives::{coin::Coin, networks::NetworkId, policy::Policy}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused imports?
validator/tests/mock.rs
Outdated
@@ -24,9 +24,11 @@ use nimiq_test_utils::{ | |||
}, | |||
}; | |||
use nimiq_time::{sleep, timeout}; | |||
use nimiq_transaction_builder::TransactionBuilder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
validator/tests/mock.rs
Outdated
.write() | ||
._set_publish_flag(false); | ||
|
||
events.take(30).for_each(|_| future::ready(())).await; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you can take 50 here and get in the red state immediately. Testing if the validator got the yellow status is already covered in another test.
8955533
to
090ee97
Compare
Track the number of blocks that are succesfully produced when changing the validator health
When a validator is deactivated, the reactivate transaction will have a delay based on the number of consecutive deactivations the validator has experienced in the current epoch. The amount of delayed blocks is of quadratic nature
090ee97
to
265abb1
Compare
The validator health is used to track the overall validator health based on the number of consecutive deactivations of a validator on a per epoch basis.
The number of consecutive deactivations would cause a delay in terms of when the reactivation transaction is sent.
Pull request checklist
clippy
andrustfmt
warnings.